var mainArray = new Array();
var currItem = 0;
var timeout = 5;

function startRequest(param)
{
  var rssDiv = document.getElementById("rssBox");
  rssDiv.innerHTML = "Trwa wczytywanie danych...";
  url = "http://localhost/dane.php?url=" + param;
  startGETRequest(url, onComplete, onEnd);
}

function startRSSShow()
{
  if(mainArray.length < 1) return;
  var item = mainArray[currItem];
  if(++currItem >= mainArray.length) currItem = 0;
  text = "<p><b>" + item['title'] + "</b></p>";
  text += "<p>" + item['pubDate'] + "</p>";
  text += "<p>" + item['description'] + "</p>";
  text += "<a href=\"" + item['link'] + "\">Wicej...</a>";

  var rssDiv = document.getElementById("rssBox");
  rssDiv.innerHTML = text;
  setTimeout("startRSSShow();", timeout * 1000);
}

function onComplete(text, xml)
{
  if(text == 'error'){
    var rssDiv = document.getElementById("rssBox");
    rssDiv.innerHTML = "Wiadomoci RSS nie s dostpne.";
  }
  else{
    items = text.split("\n\n");
    for(i = 0; i < items.length; i++){
      tempArr = new Array();
      elements = items[i].split("\n");
      tempArr['title'] = elements[0];
      tempArr['pubDate'] = elements[1];
      tempArr['link'] = elements[2];
      tempArr['description'] = elements[3];
      mainArray.push(tempArr);
    }
    startRSSShow();
  }
}

function onEnd()
{
}
